package com.ransj.ndkpath.common;

import com.ransj.ndkpath.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 
 * @author w
 * 
 */
public abstract class NdkActivity extends Activity implements
		OnItemClickListener {
	protected String mActivityArray[];
	protected String mNameArray[];
	private ArrayAdapter<String> mAdapter;
	private ListView mList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initData();
		setContentView(R.layout.page_ndkactivity);
		mList = (ListView) findViewById(R.id.ndk_activity_list);
		mAdapter = new ArrayAdapter<String>(this, R.layout.item_ndk_activity, R.id.item_ndk_activity_name,
				mNameArray);
		mList.setAdapter(mAdapter);
		mList.setOnItemClickListener(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		directToActivity(arg2);
	}

	private void directToActivity(int index) {
		try {
			String activity = mActivityArray[index];
			Intent intent = new Intent(this, Class.forName(activity));
			startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(this, "change activty :" + index + " error",
					Toast.LENGTH_SHORT).show();
		}
	}

	protected abstract void initData();
}
